# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=virt-manager
pkgver=4.0.0
pkgrel=0
pkgdesc="GUI for managing virtual machines"
url="https://virt-manager.org/"
arch="noarch !s390x !riscv64" # spice-gtk
license="GPL-2.0-or-later"
depends="python3 $pkgname-common spice-gtk vte3 py3-cairo gtk-vnc>=0.5.2-r2
	gtksourceview4 qemu-img"
_common_deps="libvirt-glib py3-libxml2 py3-libvirt py3-gobject3 py3-requests
	libosinfo"
makedepends="intltool glib py3-docutils py3-setuptools"
checkdepends="
	xorriso
	libosinfo-dev
	py3-gobject3
	py3-libvirt
	py3-libxml2
	py3-pytest
	py3-requests
"
subpackages="
	$pkgname-doc
	$pkgname-lang
	$pkgname-common
	virt-install:virt_install
	$pkgname-bash-completion:bashcomp:noarch
	"
source="https://releases.pagure.org/virt-manager/virt-manager-$pkgver.tar.gz
	drop-unfiltered-sgio.patch
	fix-latest-libvirt-xml-output.patch
	"

case "$CARCH" in
	# py3-libvirt is not available
	s390x) options="$options !check"
esac

# secfixes:
#   2.2.1-r0:
#     - CVE-2019-10183

build() {
	python3 setup.py build
}

check() {
	_skipped_tests="
		not testAlterCpuMode
		and not testCLI0004virt_install_many_devices
		and not testCLI0020virt_install_cpu_rhel7_default
		and not testCLI0388virt_xml_edit_cpu_host_copy
		and not testCLI0402virt_xml_edit_simple_features
		and not testCLI0454virt_xml_add_host_device
	"

	python3 -m pytest -k "$(echo $_skipped_tests | tr -d '\n')"
}

package() {
	python3 setup.py --no-update-icon-cache --no-compile-schemas install --root "$pkgdir"
	python3 -m compileall "$pkgdir/usr/share/virt-manager"
	python3 -O -m compileall "$pkgdir/usr/share/virt-manager"
}

common() {
	pkgdesc="Common files used by virt-manager and virt-install"
	depends="$_common_deps"
	mkdir -p "$subpkgdir"/usr/share/virt-manager "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/share/virt-manager/virtinst \
		"$subpkgdir"/usr/share/virt-manager
}

virt_install() {
	pkgdesc="Utilities for installing virtual machines"
	depends="$pkgname-common=$pkgver-r$pkgrel"
	mkdir -p "$subpkgdir"/usr/share/virt-manager "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/virt-install \
		"$pkgdir"/usr/bin/virt-clone \
		"$subpkgdir"/usr/bin/
}

bashcomp() {
	depends=""
	pkgdesc="Bash completions for $pkgname"
	install_if="$pkgname=$pkgver-r$pkgrel bash-completion"

	amove usr/share/bash-completion/completions
}

sha512sums="
115dc3feb499bb2f1f6df537bffe150d23b9b568fe8047d43577a138ff9b9180b10259dde3476136cdc85750576da1104e81a8c2f5761b4f2a89852467761f81  virt-manager-4.0.0.tar.gz
0d41a232758285e65dd245e83e9101635c0d7eb46ad351b1692d34b72ec2ce6bddae1eb8ca9897f476f74c8178da142215ce07e4933236440ca9369598498c85  drop-unfiltered-sgio.patch
3106c7d3d91db6c7fa3208a13869c5a84bb636a261939acd3be0a59ce7196dfa6102ec97372d762d8143cef4a1d0ef1c37f4a107c3826c23ff2ed22c6d57f914  fix-latest-libvirt-xml-output.patch
"
